home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / Aim.js < prev    next >
Encoding:
Text File  |  2002-08-20  |  8.0 KB  |  331 lines

  1. var strBundleService = null;
  2. var regionalBundle = null;
  3.  
  4.  
  5. /* 
  6.  * Name: aimRDFSession
  7.  * Arguments: None
  8.  * Description:
  9.  * Returns: the NC:AIM/session resource
  10.  * Author: syd@netscape.com 5/18/2001
  11.  *
  12. */
  13.  
  14. function aimRDFSession()
  15. {
  16.     var rdf = aimRDF();
  17.     if ( rdf ) {
  18.         return rdf.GetResource("NC:AIM/Session");
  19.     }
  20.     return null;
  21. }
  22.  
  23. /* 
  24.  * Name: aimRDFSessionState
  25.  *
  26.  * Arguments: None
  27.  *
  28.  * Description:
  29.  *
  30.  * Returns: the OnlineState resource
  31.  *
  32.  * Author: syd@netscape.com 5/18/2001
  33.  *
  34. */
  35.  
  36. function aimRDFSessionState()
  37. {
  38.     var rdf = aimRDF();
  39.     if ( rdf ) {
  40.         return rdf.GetResource("http://home.netscape.com/NC-rdf#OnlineState");
  41.     }
  42.     return null;
  43. }
  44.  
  45. /* 
  46.  * Name: aimRDFWarningStatus
  47.  *
  48.  * Arguments: None
  49.  *
  50.  * Description:
  51.  *
  52.  * Returns: the nsIRDF service
  53.  *
  54.  * Author: syd@netscape.com 5/18/2001
  55.  *
  56. */
  57.  
  58. function aimRDFWarningStatus()
  59. {
  60.     var rdf = aimRDF();
  61.     if ( rdf ) {
  62.         return rdf.GetResource("http://home.netscape.com/NC-rdf#Warning");
  63.     }
  64.     return null;
  65. }
  66.  
  67. /* 
  68.  * Name: aimGetStrBundle(path)
  69.  * Arguments: path
  70.  * Description:
  71.  * Returns: 
  72.  *
  73. */
  74.  
  75. function aimGetStrBundle(path)
  76. {
  77.   var strBundle = null;
  78.   if (!strBundleService) {
  79.       try {
  80.           strBundleService =
  81.               Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
  82.           strBundleService = 
  83.               strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
  84.       } catch (ex) {
  85.           return null;
  86.       }
  87.   }
  88.   strBundle = strBundleService.createBundle(path); 
  89.   if (!strBundle) {
  90.       return  null;
  91.   }
  92.   return strBundle;
  93. }
  94.  
  95. function aimRegionString(name)
  96. {
  97.     if (!regionalBundle) {
  98.         regionalBundle = aimGetStrBundle("chrome://aim-region/locale/region.properties");
  99.     }
  100.  
  101.     if (regionalBundle) {
  102.         try {
  103.             return regionalBundle.GetStringFromName(name);
  104.         } catch (ex) {
  105.               return null;
  106.         }
  107.     }
  108.     return "";
  109. }
  110.  
  111. function aimGetArgs(data)
  112. {
  113.     var args = new Object();
  114.     var pairs = data.split(",");
  115.     
  116.     for (var i = pairs.length - 1; i >= 0; i--)
  117.     {
  118.         var pos = pairs[i].indexOf('=');
  119.         if (pos == -1)
  120.             continue;
  121.         var argname = pairs[i].substring(0, pos);
  122.         var argvalue = pairs[i].substring(pos + 1);
  123.         if (argvalue.charAt(0) == "'" && argvalue.charAt(argvalue.length - 1) == "'")
  124.             args[argname] = argvalue.substring(1, argvalue.length - 1);
  125.         else
  126.             try {
  127.               args[argname] = unescape(argvalue);
  128.             } catch (e) {
  129.               args[argname] = argvalue;
  130.             }
  131.     }
  132.     return args;
  133. }
  134.  
  135. function aimString(name)
  136. {
  137.  
  138.     var myAimSession = aimSession();
  139.     if ( myAimSession ) {
  140.         var pIStringBundle = aimSession().QueryInterface(Components.interfaces.nsIStringBundle);
  141.         if (pIStringBundle) {
  142.       var connection= getCurrentSessionType();
  143.       if (connection == "AIM")
  144.               return pIStringBundle.GetStringFromName(name);
  145.       if (connection =="ICQ")
  146.         {
  147.           var icqname= name+"_ICQ";
  148.           try {
  149.             if (pIStringBundle.GetStringFromName(icqname)){
  150.               return pIStringBundle.GetStringFromName(icqname);
  151.             }
  152.           }
  153.           catch (e)
  154.           {
  155.             //do nothing when msg_ICQ does not exist - the next return will give the msg and cover that case
  156.           }
  157.           return pIStringBundle.GetStringFromName(name);
  158.         }
  159.       }
  160.     }
  161.     return "";
  162. }
  163.  
  164. function aimErrorBox(errorText)
  165. {
  166.     top.alert(errorText);
  167. }
  168.  
  169. /* Global menu commands. Menu commands that might be useful to multiple apps go here */
  170.  
  171. function aimCmdNewBrowser(url)
  172. {
  173.     var Browser_pref=null;
  174.     try
  175.     {
  176.     Browser_pref = Components.classes["@mozilla.org/preferences-service;1"];
  177.     if (Browser_pref)       Browser_pref = Browser_pref.getService();
  178.     if (Browser_pref)       Browser_pref = Browser_pref.QueryInterface(Components.interfaces.nsIPrefBranch);
  179.     }
  180.     catch (ex)
  181.     {
  182.     Browser_pref = null;
  183.     }
  184.  
  185.     if (Browser_pref.getBoolPref("network.protocols.useSystemDefaults"))
  186.   {
  187.       var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI); 
  188.         uri.spec=url;
  189.         aimAdminManager().LoadDefaultBrowser(uri);
  190.     }
  191.     else
  192.         window.openDialog( "chrome://navigator/content/navigator.xul", "_blank", "chrome,all,dialog=no", url);
  193. }
  194.  
  195.  
  196. function aimCmdNewEmail()
  197. {
  198.     openDialog("chrome://messenger/content/messengercompose/messengercompose.xul", "");
  199. }
  200.  
  201.  
  202. //SURESH: This is a hack ;-) it will work fine tgh.
  203. //The backend datasource code shd have the ability to return the #of groups. Add it later on.
  204. //The way it works here is: we checked the first index (0) to see it contains something other than Offline.
  205. function aimCheckForGroupCount()
  206. {
  207.   var tree = getSelectedTreeName();
  208.   var col = getSelectedTabName();
  209.   var view = tree.treeBoxObject.view;
  210.   var firstLevel = view.getLevel(0);
  211.   var firstText = view.getCellText(0, col);
  212.   if ((firstLevel == 0) && (firstText != "Offline"))
  213.     return true;
  214.   else
  215.     return false;
  216. }
  217.  
  218. /* returns the selected groups*/
  219.  
  220. function aimGetSelectedBuddyGroups()
  221. {
  222.   var tree = getSelectedTreeName();
  223.   var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  224.   if (rangeCount == 0)
  225.     return null;
  226.   var groups = new Array();
  227.   var count = 0; 
  228.   var col = getSelectedTabName();
  229.   var view = tree.treeBoxObject.view;
  230.   for(var i = 0; i < rangeCount; i++) {
  231.     var startIndex = {};
  232.     var endIndex = {};
  233.     tree.treeBoxObject.selection.getRangeAt(i, startIndex, endIndex);
  234.     for (var j = startIndex.value; j <= endIndex.value; j++) {
  235.       var level = view.getLevel(j);
  236.       if (level == 0) {
  237.         //first see whether the selection is a group by checking the level
  238.         //var colName = view.getCellText(j, col);
  239.         var groupResource = GetBuddyResource(tree, j);
  240.         var colName = GetBuddyAttribute(tree, groupResource, "Name");
  241.         if (colName != "Offline")
  242.           // ignore if Offline group is selected.
  243.           groups[count++] = colName;
  244.       }
  245.     }
  246.   }
  247.  
  248.   return groups;
  249. }
  250.  
  251.  
  252. // this function tries to find where the groups data in the tree starts, 
  253. // and returns the node, else null. 
  254.  
  255. function aimBuddyTreeFindGroups( tree )
  256. {
  257.     if ( !tree ) {
  258.         return( null);
  259.     }
  260.  
  261.     else if ( !tree.childNodes )
  262.     {
  263.         return( null );
  264.     }
  265.  
  266.     for ( var i = 0; i < tree.childNodes.length; i++ ) {
  267.         if ( tree.childNodes[i].nodeName == "treechildren" ) {
  268.             return( tree.childNodes[i].childNodes );
  269.         }
  270.     }
  271.     return( null );
  272. }
  273.  
  274. function aimGlobalCmdStartupWizard()
  275. {
  276.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  277.     var    windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
  278.     var topWindow = windowManagerInterface.getMostRecentWindow("Aim:StartupWizard");
  279.   if(topWindow)
  280.     topWindow.focus();
  281.   else{
  282.     var testingWizard = aimPrefsManager().GetBoolPref("aim.session.testingregistrationwizard", null, true);
  283.     if(testingWizard){
  284.        window.openDialog('chrome://aim/content/migration.xul','CPW','chrome,titlebar,resizable=yes',document);
  285.        }
  286.        else{
  287.           window.openDialog('chrome://aim/content/migrationWizard.xul','CPW','chrome,titlebar,resizable=yes',document);
  288.        }
  289.     }
  290. }
  291.  
  292. function ClearMenuList( menulist )
  293. {
  294.     if ( menulist ) {
  295.         menulist.selectedItem = null;
  296.         while( menulist.firstChild )
  297.             menulist.removeChild( menulist.firstChild );
  298.     }
  299. }
  300.  
  301. /* 
  302.  * Name: aimRDFSession
  303.  * Arguments: None
  304.  * Description:
  305.  * Returns: the NC:AIM/session resource
  306.  * Author: syd@netscape.com 5/18/2001
  307.  *
  308. */
  309. function AppendStringToMenulist(menulist, string)
  310. {
  311.   if (menulist) {
  312.     var menupopup = menulist.firstChild;
  313.     // May not have any popup yet -- so create one
  314.     if (!menupopup) {
  315.       menupopup = document.createElement("menupopup");
  316.       if (menupopup)
  317.         menulist.appendChild(menupopup);
  318.       else {
  319.         return null;
  320.       }
  321.     }
  322.     menuItem = document.createElement("menuitem");
  323.     if (menuItem) {
  324.       menuItem.setAttribute("label", string);
  325.       menupopup.appendChild(menuItem);
  326.       return menuItem;
  327.     }
  328.   }
  329.   return null;
  330. }
  331.